/**
 * 
 */
package com.netflexitysolutions.amazonws.sdb.internal.operations;

import com.amazonaws.sdb.doc._2009_04_15.CreateDomain;
import com.amazonaws.sdb.doc._2009_04_15.CreateDomainResponse;
import com.amazonaws.sdb.doc._2009_04_15.ResponseMetadata;
import com.netflexitysolutions.amazonws.sdb.Domain;
import com.netflexitysolutions.amazonws.sdb.SimpleDB;
import com.netflexitysolutions.amazonws.sdb.Statistics;

/**
 * @author netflexity
 *
 */
public class CreateDomainOperation extends OperationExecutor<CreateDomain, Domain>{
	
	private Domain domain;
	
	/**
	 * @param simpleDB
	 * @param domainName
	 */
	public CreateDomainOperation(SimpleDB simpleDB, String domainName) {
		super(simpleDB);
		this.domain = new Domain(domainName);
	}
	
	/* (non-Javadoc)
	 * @see com.netflexitysolutions.amazonws.sdb.internal.OperationExecutor#call(java.lang.Object)
	 */
	@Override
	protected Domain call(CreateDomain request) {
		// Prepare request.
		request.setDomainName(domain.getName());
		
		// Invoke operation.
		CreateDomainResponse response = getSimpleDB().getService().createDomain(request);
		if(response != null){
			ResponseMetadata metadata = response.getResponseMetadata();
			if(metadata != null){
				this.stats = new Statistics(metadata.getRequestId(), metadata.getBoxUsage());
			}
		}
		return domain;
	}
}
